﻿using System;
using System.Collections.Generic;
using System.Windows;

namespace Sonce.Common
{
    /// <summary>
    /// This class represents initial parameters.
    /// </summary>
    public static class InitParams
    {
        #region Properties
        /// <summary>
        /// Gets a skin name or Uri.
        /// </summary>
        public static string Skin
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets a url prefix to complete relative Uris.
        /// </summary>
        public static string UriPrefix
        {
            get;
            private set;
        }
        #endregion

        #region Methods
        /// <summary>
        /// Fill properties from a IDictionary.
        /// </summary>
        /// <param name="initParams">IDictionary from application startup arguments.</param>
        public static void Fill(IDictionary<string, string> initParams)
        {
            if (initParams != null && initParams.Count > 0)
            {
                Skin = (initParams.ContainsKey("Skin") ? initParams["Skin"] : null);
                UriPrefix = (initParams.ContainsKey("UriPrefix") ? initParams["UriPrefix"] : null);

                //Set the url prefix if empty
                if (string.IsNullOrEmpty(UriPrefix))
                {
                    //Use application's root as uri prefix
                    string uri = Application.Current.Host.Source.AbsoluteUri;
                    int pos = uri.IndexOf("/");
                    if (pos >= 0)
                    {
                        UriPrefix = uri.Remove(pos + 1, uri.Length - pos - 1);
                    }
                }
            }
        }
        #endregion
    }
}
